//
//  HHHttpCom.h
//  Pod
//
//  Created by Basic on 2017/3/11.
//  Copyright © 2017年 naruto. All rights reserved.
//  zhouhua 网络业务组件-http引擎类

#import "BCBaseHttpEngine.h"
#import "BCHttpFileModel.h"
#import "BCHttpRequestModel.h"
#import "BCHttpResponseModel.h"
#import "HHHttpConfigProtocol.h"
#import "HHHttpConfig.h"
#import "BCBaseRequestDefines.h"

NS_ASSUME_NONNULL_BEGIN

#define kHHHttpComInstance [HHHttpCom sharedInstance]

@interface HHHttpCom : BCBaseHttpEngine

/**
 http config
 */
@property (nonatomic, strong) HHHttpConfig *httpConfig;
/** 配置协议 */
@property (nonatomic, weak) id<HHHttpConfigProtocol>    configDelegate;

//MARK: - system
///单例，同sharedInstance 兼容swift
+ (nonnull instancetype)shared;

//MARK: - 初始化
///初始化
- (void)hh_setup;

/// 设置请求投
/// @param value value description
/// @param field field description
- (void)setValue:(nullable NSString *)value forHTTPHeaderField:(NSString *)field;

///  是否激活日志 默认开启（不建议全局控制日志，建议指定参数 kZHNetwork_NoSaveLog）
/// @param enable 是否开启
- (void)enableLogs:(BOOL)enable;

//MARK: - get 请求
/// 请求url ，get方式
/// @param url url地址
/// @param param 参数
/// @param complateAction complateAction description
/// @param target target description
+ (BCBaseRequestOperation *)getURL:(NSString *_Nullable)url withParam:(NSDictionary *_Nullable)param withComplate:(void (^_Nullable)(BCHttpRequestModel *, BCHttpResponseModel *))complateAction withTarget:(id _Nullable)target;

//MARK: - post 请求

/// @brief  根据api等等参数 发请求 默认form 模式
/// @param api api名称
/// @param param 参数集合
/// @param complateAction complateAction 完成action
/// @param target BCBaseRequest
+ (BCBaseRequestOperation *)requestAPI:(NSString *_Nullable)api withParam:(NSDictionary *_Nullable)param withComplate:(void (^_Nullable)(BCHttpRequestModel *request, BCHttpResponseModel *response))complateAction withTarget:(id _Nullable)target;

/// 根据url POST请求 form 模式
/// @param url url description
/// @param param  参数集合
/// @param complateAction 完成回调
/// @param target target description
+ (BCBaseRequestOperation *)requestUrl:(NSString *_Nullable)url withParam:(NSDictionary *_Nullable)param withComplate:(void (^_Nullable)(BCHttpRequestModel *, BCHttpResponseModel *))complateAction withTarget:(id _Nullable)target;

/// 根据url POST请求  json模式
/// @param url url description
/// @param param 参数集合
/// @param complateAction 完成回调
/// @param target target description
+ (BCBaseRequestOperation *)requestJsonUrl:(NSString *_Nullable)url withParam:(NSDictionary *_Nullable)param withComplate:(void (^_Nullable)(BCHttpRequestModel *, BCHttpResponseModel *))complateAction withTarget:(id _Nullable)target;


/// 根据url POST请求  json模式
/// @param url url description
/// @param param 参数集合
/// @param complateAction 完成回调
/// @param target target description
+ (BCBaseRequestOperation *)requestPut:(NSString *_Nullable)url withParam:(NSDictionary *_Nullable)param withComplate:(void (^_Nullable)(BCHttpRequestModel *, BCHttpResponseModel *))complateAction withTarget:(id _Nullable)target;

/// POST请求，添加header
/// @param url 完整URL(host+api)
/// @param contentType 请求内容类型
/// @param headers 自定义headers,会覆盖header相同的key
/// @param param post参数
/// @param complateAction 完成回调
/// @param target 关联目标对象
+ (BCBaseRequestOperation *)requestURL:(NSString *_Nullable)url
                       withContentType:(BCRequestContentType)contentType
                           withHeaders:(NSDictionary<NSString *, id> *_Nullable)headers withParam:(NSDictionary<NSString *, id> *_Nullable)param withComplate:(void (^_Nullable)(BCHttpRequestModel *, BCHttpResponseModel *))complateAction withTarget:(id _Nullable)target;


/// POST请求，添加header
/// @param url 完整URL(host+api)
/// @param contentType 请求内容类型
/// @param headers 自定义headers,会覆盖header相同的key
/// @param param post参数
/// @param complateAction 完成回调
/// @param target 关联目标对象
+ (BCBaseRequestOperation *)requestURLPut:(NSString *_Nullable)url
                       withContentType:(BCRequestContentType)contentType
                           withHeaders:(NSDictionary<NSString *, id> *_Nullable)headers withParam:(NSDictionary<NSString *, id> *_Nullable)param withComplate:(void (^_Nullable)(BCHttpRequestModel *, BCHttpResponseModel *))complateAction withTarget:(id _Nullable)target;

//MARK: - DELETE 请求
/// 请求URL，DELETE模式
/// @param url 地址
/// @param param 参数
/// @param complateAction 完成回调
/// @param target 关联目标对象
+ (BCBaseRequestOperation *)deleteURL:(NSString *_Nullable)url withParam:(NSDictionary *_Nullable)param withComplate:(void (^_Nullable)(BCHttpRequestModel *, BCHttpResponseModel *))complateAction withTarget:(id _Nullable)target;

//MARK: - 上传文件请求 - http 上传

/// 上传图片
/// @param image 图片对象
/// @param uploadProgress 上传进度
/// @param complete callback
+ (void)uploadImage:(UIImage *)image progress:(void (^_Nullable)(float percent))uploadProgress complete:(void (^_Nullable)(BOOL success, NSString *imageUrl))complete;

/// 上传文件
/// @param filePath 文件路径
/// @param uploadProgress 上传进度
/// @param complete callback
+ (void)uploadFileWithPath:(NSString *)filePath progress:(void (^_Nullable)(float percent))uploadProgress complete:(void (^_Nullable)(BOOL success, NSString *filePath, NSString *fileURL))complete;

/// 上传文件
/// @param fileModel 文件对象
/// @param uploadProgress 上传进度
/// @param complete callback
+ (void)uploadWithFile:(BCHttpFileModel *)fileModel progress:(void (^_Nullable)(float percent))uploadProgress complete:(void (^_Nullable)(BCHttpResponseModel *response, BCHttpFileModel *fileModel))complete;

/// 批量上传文件
/// @param fileModels 文件对象集合
/// @param uploadProgress 上传进度
/// @param complete callback
+ (void)uploadWithFiles:(NSArray<BCHttpFileModel *> *)fileModels progress:(void (^_Nullable)(float percent))uploadProgress complete:(void (^_Nullable)(BCHttpResponseModel *response, NSArray<BCHttpFileModel *> *fileModels))complete;

/// 上传文件
/// @param uploadURL 文件上传URL
/// @param fileModel 文件对象
/// @param params 上传参数
/// @param uploadProgress 上传进度
/// @param complete callback
+ (void)requestUploadFileURL:(NSString *)uploadURL withFileModel:(BCHttpFileModel *)fileModel withParams:(NSDictionary *_Nullable)params withProgress:(void (^)(float))uploadProgress withComplate:(void (^)(BCHttpRequestModel *_Nonnull, BCHttpResponseModel *_Nonnull, BCHttpFileModel *_Nonnull))complete;

/// 批量上传文件
/// @param uploadURL 文件上传URL
/// @param fileModels 文件对象集合
/// @param params 上传参数
/// @param uploadProgress 上传进度
/// @param complete callback
+ (void)requestUploadFilesURL:(NSString *_Nullable)uploadURL withFileModels:(NSArray<BCHttpFileModel *> *)fileModels withParams:(NSDictionary *_Nullable)params withProgress:(void (^_Nullable)(float))uploadProgress withComplate:(void (^_Nullable)(BCHttpRequestModel *request, BCHttpResponseModel *response, NSArray<BCHttpFileModel *> *fileModels))complete;

@end

NS_ASSUME_NONNULL_END
